package com.ruoyi.project.ums.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.ums.domain.UmsAddress;
import com.ruoyi.db.ums.domain.query.UmsAddressQueryVo;
import com.ruoyi.project.ums.service.UmsAddressService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 收货地址Controller
 *
 * @author ruoyi
 * @date 2020-04-22
 */
@Api(tags="ums管理：收货地址管理")
@RestController
@RequestMapping("/ums/address")
public class UmsAddressController extends BaseController
{
    @Autowired
    private UmsAddressService umsAddressService;

    @ApiOperation("查询收货地址列表")
    @PreAuthorize("@ss.hasPermi('ums:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(UmsAddressQueryVo umsAddressQueryVo)
    {
        startPage();
        List<UmsAddress> list = umsAddressService.selectUmsAddressList(umsAddressQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出收货地址列表")
    @Log(title = "收货地址", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ums:address:export')")
    @GetMapping("/export")
    public AjaxResult export(UmsAddressQueryVo umsAddressQueryVo)
    {
        List<UmsAddress> list = umsAddressService.selectUmsAddressList(umsAddressQueryVo);
        ExcelUtil<UmsAddress> util = new ExcelUtil<UmsAddress>(UmsAddress.class);
        return util.exportExcel(list, "address");
    }

    @ApiOperation("获取收货地址详细信息")
    @Log(title = "收货地址", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('ums:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(umsAddressService.selectUmsAddressById(id));
    }

    @ApiOperation("新增收货地址")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('ums:address:add')")
    @PostMapping
    public AjaxResult add(@RequestBody UmsAddress umsAddress)
    {
        return toAjax(umsAddressService.insertUmsAddress(umsAddress));
    }

    @ApiOperation("修改收货地址")
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('ums:address:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody UmsAddress umsAddress)
    {
        return toAjax(umsAddressService.updateUmsAddress(umsAddress));
    }

    @ApiOperation("删除收货地址")
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('ums:address:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(umsAddressService.deleteUmsAddressByIds(ids));
    }
}
